package charazay.tool.managers.site;

import java.io.IOException;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

import charazay.tool.managers.XML.LoginContentHandler;

public class LoginSiteManager extends GenericSiteManager {
	private int teamid = 0;
	
	public LoginSiteManager() {
	}
	
	public int request(String username, String password) {
		String request_url = buildURL(username, password, null, null );
		XMLReader saxReader = null;
		try {
			saxReader = XMLReaderFactory.createXMLReader("com.sun.org.apache.xerces.internal.parsers.SAXParser");
			saxReader.setContentHandler(new LoginContentHandler());
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			saxReader.parse(request_url);
			teamid = ((LoginContentHandler)saxReader.getContentHandler()).getTeamId();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return teamid;
	}
}
